package com.beiben.experiment.frock.controller;

import java.util.List;

import com.beiben.experiment.equipment.domain.Equipment;
import com.beiben.experiment.equipment.domain.StateVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.beiben.experiment.frock.domain.Frock;
import com.beiben.experiment.frock.service.IFrockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 工装信息Controller
 * 
 * @author 熊国强
 * @date 2020-11-11
 */
@RestController
@RequestMapping("/experiment/frock")
public class FrockController extends BaseController
{
    @Autowired
    private IFrockService frockService;

    /**
     * 查询工装信息列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:frock:list')")
    @GetMapping("/list")
    public TableDataInfo list(Frock frock)
    {
        startPage();
        List<Frock> list = frockService.selectFrockList(frock);
        return getDataTable(list);
    }

    /**
     * 导出工装信息列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:frock:export')")
    @Log(title = "工装信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Frock frock)
    {
        List<Frock> list = frockService.selectFrockList(frock);
        ExcelUtil<Frock> util = new ExcelUtil<Frock>(Frock.class);
        return util.exportExcel(list, "frock");
    }

    /**
     * 获取工装信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:frock:query')")
    @GetMapping(value = "/{frockId}")
    public AjaxResult getInfo(@PathVariable("frockId") Long frockId)
    {
        return AjaxResult.success(frockService.selectFrockById(frockId));
    }

    /**
     * 新增工装信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:frock:add')")
    @Log(title = "工装信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Frock frock)
    {
        return toAjax(frockService.insertFrock(frock));
    }

    /**
     * 修改工装信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:frock:edit')")
    @Log(title = "工装信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Frock frock)
    {
        return toAjax(frockService.updateFrock(frock));
    }

    /**
     * 删除工装信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:frock:remove')")
    @Log(title = "工装信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{frockIds}")
    public AjaxResult remove(@PathVariable Long[] frockIds)
    {
        return toAjax(frockService.deleteFrockByIds(frockIds));
    }

    /**
     * 导入试验设备\计量设备信息
     */
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<Frock> util = new ExcelUtil<Frock>(Frock.class);
        return util.importTemplateExcel("工装信息数据");
    }

    @Log(title = "工装导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('experiment:frock:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Frock> util = new ExcelUtil<Frock>(Frock.class);
        List<Frock> frockList = util.importExcel(file.getInputStream());
        String message = frockService.importFrock(frockList, updateSupport);
        return AjaxResult.success(message);
    }

    /**
     * 修改工装信息 使用状态
     */
//    @PreAuthorize("@ss.hasPermi('experiment:frock:state')")
    @PostMapping("/changeState")
    public AjaxResult changeState(@RequestBody StateVo stateVo)
    {
        return toAjax(frockService.updateFrockState(stateVo.getIds(),stateVo.getState()));
    }
}
